package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.yootung.YootungConsumptiveForecast;
import com.ucredit.babel.common.model.third.yootung.YootungConsumptiveForecastData;
import com.ucredit.babel.common.model.third.yootung.YootungConsumptiveForecastRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 佑棠消费能力预测
 *
 * @author renzhanzheng
 */

public class YootungConsumptiveForecastParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 佑棠消费能力预测
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */


    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        YootungConsumptiveForecastRecord obj = (YootungConsumptiveForecastRecord) model;
        YootungConsumptiveForecastData data = obj.getData() == null ? new YootungConsumptiveForecastData() : obj.getData();
        YootungConsumptiveForecast data1 = data.getData() == null ? new YootungConsumptiveForecast() : data.getData();


        StringBuilder sb = getBaseInfo(obj, successful);
        //交易相应代码
        sb.append(data.getCode() == null ? "" : data.getCode()).append(CRT001);
        //描述信息
        sb.append(data.getMsg() == null ? "" : data.getMsg()).append(CRT001);
        //验证结果代码
        sb.append(data1.getCode() == null ? "" : data1.getCode()).append(CRT001);
        //验证结果描述
        sb.append(data1.getMsg() == null ? "" : data1.getMsg()).append(CRT001);
        //交易流水号
        sb.append(data1.getGlobalNo()== null ? "" : data1.getGlobalNo()).append(CRT001);
        //评分
        sb.append(data1.getScore()== null ? "" : data1.getScore()).append(CRT001);

        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;

    }

    @Override
    public String getTableName() {
        return "kafka_babel_youtang_xiaofeiyuce_inc";
    }

    @Override
    public String getType() {
        return RecordType.YOOTUNG_ONSUMPTIVE_FORECAST_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "佑棠消费能力预测";
    }
}
